// Register page module
// ====================

define(['zepto', 'sui', 'submitForm'], function($) {
  return {
    init: function(data) {
      this.data = data;
      this.initPage();
    },
    initPage: function() {
      var that = this;
      $(".lock").click(function() {
         $.toast("亲亲，要先完成现阶段课程才能解锁哦");
      })
      
      $(document).on("click", ".course-list li a.join-group", function(e) {
        requestHref= $(e.currentTarget).data("url")
        if(!$(e.currentTarget).hasClass("lock")) {
          $.modal({
            title: '<div style="font-size: .7rem; margin-top: 1rem;">扫码加入微信群，<br/>获取更多健身技能~</div>',
            text: '<div><img src="'+ that.data.qrcode +'" style="width: 8rem; height: 8rem; margin-top: 0; margin-bottom: 1rem;"></div>',
            buttons: [
              {
                text: '我已加入群',
                onClick: function() {
                  $.ajax({
                    type: 'POST',
                    url: window.__CTX__.root + '/courses/join-group' ,
                    success: function(data){
                      window.location.href = requestHref
                    },
                    error: function(res){
                      $.toast(res.message)
                    }
                  })
                  
                }
              },
              {
                text: '继续访问',
                close: true,
                onClick: function() {
                  window.location.href = requestHref
                }
              }
            ]
          })
        }
      })
      
      
    }
   
  }
})